package com.leapp.sk.ui.activity.personal
import android.os.Bundle
import cc.vv.lkbasecomponent.http.LKHttp
import cc.vv.lkbasecomponent.http.lib.setting.Settings
import cc.vv.lkbasecomponent.util.LKSPUtil
import cc.vv.lklibrary.http.base.okhttpfactory.plugins.httpplugin.MediaTypeWrap
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.leapp.sk.R
import com.leapp.sk.app.CLASS_DETIAL_MEMBER
import com.leapp.sk.bean.ClassDetialDataEntity
import com.leapp.sk.bean.request.classs.ClassDetialRequestEntity
import com.leapp.sk.bean.response.classs.ContanctResponseEntity
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.sever.personal.ContanctSever
import com.example.util.finallist.KEY_CLASS_TYPE
import com.example.util.finallist.SKCODE_200
import com.leapp.sk.viewdelegate.personal.ContanctDelegate

/**
 * 联系人
 * @author  chaohaipeng  on 2018/8/21.
 */
class ContanctActivity:BaseActivityMVP<ContanctDelegate>() {
    /**
     * 数据源
     */
    val mutableListOf = mutableListOf<ClassDetialDataEntity>()
    override fun bindEvenListener() {
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.app_mail_list))
    }

    override fun initDate() {
        viewDelegate.initAdapter(this,mutableListOf)
        httpClassDetial()
    }

    override fun getDelegateClass(): Class<ContanctDelegate> {
        return ContanctDelegate::class.java
    }

    /**
     * 班级详情
     */
    private fun httpClassDetial() {
       val type= ""+ LKSPUtil.getInstance().getInt(KEY_CLASS_TYPE, 0)
        val classDetialRequestEntity = ClassDetialRequestEntity()
        classDetialRequestEntity.id=classDetialRequestEntity.userId
        classDetialRequestEntity.parentNum=5
        classDetialRequestEntity.type=type
        LKHttp.post(CLASS_DETIAL_MEMBER, classDetialRequestEntity, ContanctResponseEntity::class.java, object : BaseCallBack<ContanctResponseEntity>(this) {
            override fun onSuccess(url: String?, resultText: String?, obj: ContanctResponseEntity?) {
                super.onSuccess(url, resultText, obj)
                if (obj?.code == SKCODE_200) {
                    val contanctData = ContanctSever.getInstance().getContanctData(obj)
                    mutableListOf?.addAll(contanctData)
                    viewDelegate?.notifyAdapter()
                }else{
                    LKToastUtil.showToastShort(obj?.message)
                }
            }
            override fun onFailure(url: String?, isLoading: Boolean, exceptionStr: String?) {
                super.onFailure(url, isLoading, exceptionStr)
                LKToastUtil.showToastShort(resources.getString(R.string.app_net_erro))
            }
        }
                , true, Settings(MediaTypeWrap.MEDIA_TYPE_FORM))

    }




}